include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=gpio-control
PKG_VERSION:=1.0
PKG_RELEASE:=1

PKG_MAINTAINER:=OpenWrt Developer
PKG_LICENSE:=GPL-2.0

include $(INCLUDE_DIR)/package.mk

define KernelPackage/gpio-control
	SUBMENU:=Other modules
	TITLE:=MT7621 GPIO Control Driver
	FILES:=$(PKG_BUILD_DIR)/gpio-control.ko
	AUTOLOAD:=$(call AutoLoad,10,gpio-control)
	DEPENDS:=@TARGET_ramips_mt7621
endef

define KernelPackage/gpio-control/description
	Kernel driver for MT7621 that initializes GPIO22 to low during boot
	and sets it to high after system startup completion.
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Compile
	$(MAKE) -C "$(LINUX_DIR)" \
		ARCH="$(LINUX_KARCH)" \
		CROSS_COMPILE="$(TARGET_CROSS)" \
		M="$(PKG_BUILD_DIR)" \
		modules
endef

define KernelPackage/gpio-control/install
	$(INSTALL_DIR) $(1)/lib/modules/$(LINUX_VERSION)
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/gpio-control.ko $(1)/lib/modules/$(LINUX_VERSION)/
endef

$(eval $(call KernelPackage,gpio-control))

define Package/gpio-control-utils
	SECTION:=utils
	CATEGORY:=Utilities
	TITLE:=GPIO Control Utilities
	DEPENDS:=+kmod-gpio-control
	MAINTAINER:=EpPluto
endef

define Package/gpio-control-utils/description
	Userspace utilities for GPIO control on MT7621 devices.
endef

define Package/gpio-control-utils/install

endef


$(eval $(call BuildPackage,gpio-control-utils))
